﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using ITOMMS.Entity;
using Watson.Core.Tools;

namespace ITOMMS.Web.Finance
{
    public partial class AccountReceivableList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataShow(GetSearchSql());
            }
        }
        private void DataShow(string searchSql)
        {
            tb往来单位应收账款Entity entity = new tb往来单位应收账款Entity();
            AspNetPager1.RecordCount = entity.GetTotalRecords();
            this.dgdaoim_sus_plyedr.DataSource = entity.GetAllByQuery(searchSql, "order by id desc", 10, AspNetPager1.CurrentPageIndex);
            dgdaoim_sus_plyedr.DataBind();

        }
 

        private string GetSearchSql()
        {
             
            StringBuilder sb = new StringBuilder();
            sb.Append(" 1=1 ");
            if (txt起始时间.Text.Trim().Length > 0)
            {
                sb.Append(" and  起始时间 >= '").Append(txt起始时间.Text.Trim()).Append("'"); ;
            }
            if (txt终止时间.Text.Trim().Length > 0)
            {
                sb.Append(" and  终止时间 <= '").Append(txt终止时间.Text.Trim()).Append("'"); ;
            }

            return sb.ToString();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            DataShow(GetSearchSql());

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            DataShow(GetSearchSql());
        }

        protected void dgdaoim_sus_plyedr_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.ToString() == "del")
                {
                    if (e.CommandArgument.ToString() != "")
                    {

                        if (new tb往来单位应收账款Entity().Delete(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.succeedInfo('删除成功。',300,180,'提示',null);</script>");
                            DataShow(GetSearchSql());
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.errorInfo('删除失败。',300,180,'提示',null);</script>");
                        }

                    }
                }
            }
            catch (APPException appex)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.alert('" + appex.Message + "。',300,180,'提示',null);</script>");
            }
            catch (Exception ex)
            {
                log4netHelper.error("", ex);
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.errorInfo('删除失败。',300,180,'提示',null);</script>");
            }
        }


 

 
    }
}
